package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.Travel;
import cn.wolfcode.luowowo.article.domain.TravelContent;
import cn.wolfcode.luowowo.article.query.TravelQuery;
import cn.wolfcode.luowowo.article.service.ITravelService;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by LENOVO on 2019/8/12.
 */
@Controller
@RequestMapping("/travel")
public class TravelController {

    @Reference
    private ITravelService travelService;

    @RequestMapping("/list")
    public String list(Model model,@ModelAttribute("qo") TravelQuery qo){
//先判断页面是否有查询条件,页面没传
        if (qo.getState() ==null) {
            qo.setState(Travel.STATE_RELEASE);
        }
        System.out.println(qo.getState());

        qo.setIsPublic(true);//设置为公开

        PageInfo pageInfo = travelService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return  "travel/list";
    }


    //查询文章内容
    @RequestMapping("/getContentById")
    @ResponseBody
    public TravelContent getContentById(Long id){
        return travelService.getContent(id);
    }

    //修改内容
    @RequestMapping("/updateState")
    @ResponseBody
    public Object updateState(Long id,int state){
        travelService.updateState(id,state);

        return AjaxResult.SUCCESS;
    }

}
